﻿using System.IO;
using System.Windows.Forms;

namespace UnitTestsScenarioEditor
{
    internal class EngineInit
    {
        #region Public Fields

        public Engine.Camera.Camera camera;
        public Engine.Engine engine;
        public Form form;
        public Engine.Graphics.MaterialManager materialManager;
        public Panel panel;
        public Engine.Graphics.ShaderManager shaderManager;

        #endregion Public Fields

        #region Public Constructors

        public EngineInit()
        {
            string startupPath = Engine.Engine.GetStartupPath();
            string gameDll = "WorldRacing2.GameDll.dll";
            string destinationDirectory = startupPath + "\\Addins\\";

            // Copy shaders to unittest folder.
            //CopyAll(new DirectoryInfo(@"C:\Dev\Scenario Editor\bin\Release\"), new DirectoryInfo(@"C:\Dev\Scenario Editor\bin\UnitTests\"));
            //CopyAll(new DirectoryInfo(@"C:\Dev\Scenario Editor\bin\Release\"), new DirectoryInfo(@"C:\Dev\Scenario Editor\bin\UnitTests\"));
            //Copy gameDll do
            string newFile = destinationDirectory + gameDll;

            if (!Directory.Exists(destinationDirectory))
                Directory.CreateDirectory(destinationDirectory);

            if (File.Exists(newFile))
                File.Delete(newFile);

            File.Copy(startupPath + "\\" + gameDll, newFile, true);
            string addinName = "World Racing 2";

            this.form = new Form();
            this.panel = new Panel();
            this.form.Size = new System.Drawing.Size(500, 500);
            this.panel.Dock = DockStyle.Fill;
            this.form.Controls.Add(this.panel);
            this.engine = new Engine.Engine(this.panel, this.form.Handle);
            this.engine.addinManager.SetAddin(addinName);

            this.materialManager = new Engine.Graphics.MaterialManager(this.engine, ".\\texture\\");
            //UnitTestTerrain.materialManager.AddNewMaterial(new Engine.Graphics.Material("sample", "sample", "sample", Engine.Graphics.EnumMappingMode.material00), false);
            this.shaderManager = new Engine.Graphics.ShaderManager(addinName, ".\\shaders\\", this.engine.Grafic.Device);
            this.shaderManager.DebugName = "Unit Test Class init.";
            this.camera = new Engine.Camera.Camera();
        }

        #endregion Public Constructors

        #region Private Destructors

        ~EngineInit()
        {
            if (this.engine != null) this.engine.Dispose();
            if (this.materialManager != null) this.materialManager.Dispose();
            if (this.shaderManager != null) this.shaderManager.Dispose();
        }

        #endregion Private Destructors
    }
}